Classic Sort algorithm-pigeon nest sort pigeonhole
The principle is similar to the bucket sort, also need a very big pigeon nest [bucket sort tube This is called bucket, name doesn't matter]
The Pigeon nest is actually an array, the index position of the array represents the
Classic sort algorithm-pigeon nest sort pigeonholeThe principle is similar to the bucket sort, also need a very big pigeon nest [bucket sort tube This is called bucket, name doesn't matter]The Pigeon nest is actually an array, the index position of the array represents the value, the value of the index position indicat
Classical sorting algorithm-pig nest sorting pigeonhole sort
The principle is similar to bucket sorting. It also requires a very large Pigeon nest. [This is called Bucket in bucket sorting. the name doesn't matter.]
Pigeon nest is actually an array. The index position of the array indicates the value, and the value of the index position indicates the number of occurrences. If all the indexes are 1 or 0, the
The Pigeon Nest Sort, also known as Cardinal classification, is a sort algorithm with time complexity (Theta (n)) that is the most efficient when it is unavoidable to traverse each element and sort. However, it is useful only if the difference (or the number of values that can be mapped in the difference) is sorted in a small range. When multiple unequal elements
basic theorem of pigeon nest principle (pigeonhole Principle):
If N + 1 objects is distributed into N boxes and then at least one box contains and more of the objects.
A simple example: the birthdays of at least two people in 13 people are in the same January.
related principles of pigeon nest principle: If n objects is put into N boxes and no box gets more than one object, then each box has a object in it.
Let X and Y is finite sets and let F:x-y i
A variety of common sortTo start looking for a job, the previous learning of a variety of small knowledge to review, the following is a variety of common sort of simple implementation (bubble sort, choose sort, insert sort, hill sort, heap
C # Insert Sort bubble Sort Select sort High speed sort heap sort merge sort base Sort Hill sortThe following is a list of eight basic sorts of data structures and algorithms: Insert
The first is the Eightalgorithms.java file, the code is as follows:Import java.util.arrays;/* * Implements eight commonly used sorting algorithms: Insert sort, bubble sort, select sort, Hill sort * and quick sort, merge sort, heap
C # Insert Sort bubble Sort Select sort Quick sort Heap sort Merge sort base Sort Hill sortThe following is a list of eight basic sorts of data structures and algorithms: Insert
The first is the algorithm implementation file Sort.h, the code is as follows:/** implements eight commonly used sorting algorithms: Insert sort, bubble sort, select sort, Hill sort * and quick sort, merge sort, heap
The relationship between 8 sorts:
1, direct insertion sort
(1) Basic idea: In the set of numbers to be sorted, suppose that the front (n-1) [n>=2] number is already a row
In a good order, now you have to insert the nth number into the preceding ordered number so that the number of n
It's a good order, too. Repeat the loop until all the order is sorted.
(2) Example
(3) Implement with Java[Plain] View plain copy packagecom.njue; publicclassinserts
Package Com.wang.sort;import Java.util.arrays;public class Sort {/** * 1. Direct insertion Sort * Idea: The current number is compared with the number of rows already in the previous order, and inserted into the appropriate position * @param Arra */public void Simplesort (int[] arra) {for (int i = 1; i Eight basic sort (direct insert
Direct Insert Sort:In the sequence , assume ascending sort1) start at 0.1) If you go to begin = 3, save the Begin element to TMP, compare the element at TMP with the element size relationship at begin--, and move the begin-1 element to begin if it is 3) and so on, go through the sequence sequentially.Complexity of Time: O ()The code is as follows:
Sequence in ascending order void Insertsort (int* a,int size) {assert (a);for (int begin = 0; begin 2. Hill sortThe hill
To sort an integer element in the ArrayList collection in ascending order:
Package org.hyp.test; Import java.util.ArrayList; Import Java.util.Random; public class Mysort {private arraylist
On the sorting method, the common sorting methods are insert sort, bubble sort, quick sort, select sort, merge sort, also have heap sort, bucket sort, base
Common sort algorithm implementations (direct insert sort, bubble sort, quick sort, build big selection Sort), and several next time write on. #include "stdio.h" #include "stdlib.h" #include "malloc.h" #include Operation Result: 3 1 14 5 2 56 67 54 77 34 This is the resu
An algorithm is a set of well-defined rules that are used to solve a problem within a finite step. Popular point, that is, the process of computer problem solving. In this process, whether the formation of a problem-solving ideas or writing programs, are in the implementation of some kind of algorithm. The former is the algorithm of inference implementation, the latter is the algorithm of operation implementation.
An algorithm should have the following five important features:
1. Poor: An algori
Bubble Sort: int[] hehe={4,7,2,5,6,9,0}; for(intI=0; i){ for(intj=i+1; j){ if(hehe[i]>Hehe[j]) { inttemp=Hehe[i]; Hehe[i]=Hehe[j]; HEHE[J]=temp; } } }Insert Sortint[] a={ -,7,8,9,Ten,1,2, +}; inti,j,t,h; for(i=1; i) {T=a[i];//the number of one digit after the depositJ=i-1; while(j>=0 tA[j]) {A[j+1]=A[J];//the last digit equals the previous oneJ--; } a[j+1]=t;//if a while is made, the latter number e
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.